package offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class offer_0057_2 {
    public int[][] findContinuousSequence(int target) {
        List<List<Integer>> list=new ArrayList<>();
        LinkedList<Integer> tep=new LinkedList<>();
        int sum=0;
        for(int i=1;i<target;++i){
            if(sum<target){
                tep.add(i);
                sum+=i;
                if(sum==target) {
                    list.add(new LinkedList<>(tep));
                    sum-=tep.removeFirst();
                }
            }
            else{
                sum-=tep.removeFirst();
                if(sum==target) {
                    list.add(new LinkedList<>(tep));
                    sum-=tep.removeFirst();
                }
                --i;
            }
        }
        int len=list.size();
        int[][] result=new int[len][];
        for(int i=0;i<len;++i){
            int len1=list.get(i).size();
            int[] tem=new int[len1];
            for(int k=0;k<len1;++k){
                tem[k]=list.get(i).get(k);
            }
            result[i]=tem;
        }
        return result;
    }
}
